home *** CD-ROM | disk | FTP | other *** search
- unit PageCtl1;
-
- interface
-
- uses
- Windows, Messages, CommCtrl, SysUtils, Classes, Graphics, Controls,
- Forms, Dialogs, ComCtrls, StdCtrls, ExtCtrls;
-
- type
- TPageControlStyle = (pcsStandard, pcsOwnerDraw);
-
- TODPageControl = class(TPageControl)
- private
- FCanvas : TCanvas;
- FOnDrawItem : TDrawItemEvent;
- FStyle : TPageControlStyle;
- procedure DrawItem(Index: Integer; ARect: TRect;
- State: TOwnerDrawState);
- protected
- procedure CreateParams(var Params: TCreateParams); override;
- procedure SetStyle(Value: TPageControlStyle);
- procedure CNDrawItem(var Msg: TWMDrawItem);
- message cn_DrawItem;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure DefaultDrawTab(Index: Integer; ARect: TRect;
- State: TOwnerDrawState); virtual;
- property Canvas: TCanvas read FCanvas;
- published
- property Style: TPageControlStyle
- read FStyle write SetStyle default pcsStandard;
- property OnDrawItem: TDrawItemEvent
- read FOnDrawItem write FOnDrawItem;
- end;
-
- procedure Register;
-
- implementation
-
- constructor TODPageControl.Create(AOwner: TComponent);
- begin
- inherited;
- FStyle := pcsStandard;
- end;
-
- destructor TODPageControl.Destroy;
- begin
- //Cleanup after ourselves
- if Assigned(FCanvas) then
- FCanvas.Free;
- inherited
- end;
-
- procedure TODPageControl.DrawItem(Index: Integer; ARect: TRect;
- State: TOwnerDrawState);
- begin
- if Assigned(FOnDrawItem) then
- FOnDrawItem(Self, Index, ARect, State)
- else
- DefaultDrawTab(Index, ARect, State)
- end;
-
- procedure TODPageControl.CreateParams(var Params: TCreateParams);
- const
- OwnStyle: array[Boolean] of LongInt = (0, tcs_OwnerDrawFixed);
- begin
- inherited;
- with Params do
- Style := Style or OwnStyle[FStyle = pcsOwnerDraw];
- end;
-
- procedure TODPageControl.SetStyle(Value: TPageControlStyle);
- begin
- if Value <> FStyle then
- begin
- FStyle := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TODPageControl.CNDrawItem(var Msg: TWMDrawItem);
- var
- State: TOwnerDrawState;
- begin
- if not Assigned(FCanvas) then
- FCanvas := TCanvas.Create;
- with Msg.DrawItemStruct^ do
- begin
- //The low byte of ItemState is the bitmap that our set requires
- State := TOwnerDrawState(WordRec(Word(ItemState)).Lo);
- FCanvas.Handle := hDC;
- FCanvas.Font := Font;
- FCanvas.Brush := Brush;
- if Integer(itemID) >= 0 then
- DrawItem(itemID, rcItem, State);
- FCanvas.Handle := 0;
- end;
- end;
-
- procedure TODPageControl.DefaultDrawTab(Index: Integer;
- ARect: TRect; State: TOwnerDrawState);
- var
- S: String;
- X, Y: Integer;
- begin
- //Do a bit of default drawing when the
- //component user is'nt doing it
- FCanvas.FillRect(ARect);
- S := Pages[Index].Caption;
- X := (ARect.Right + ARect.Left - FCanvas.TextWidth(S)) div 2;
- Y := (ARect.Bottom + ARect.Top + 4 - FCanvas.TextHeight(S)) div 2;
- //Active tab has text _slightly_ higher
- if odSelected in State then
- Dec(Y, 3);
- FCanvas.TextOut(X, Y, S);
- end;
-
- procedure Register;
- begin
- RegisterComponents('Clinic', [TODPageControl]);
- end;
-
- end.